package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.BoatMachineWorkingInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IBoatMachineWorkingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 船舶工况信息Controller
 *
 * @author zjw
 * @date 2024-01-19
 */
@RestController
@RequestMapping("/system/boatMachineWorkingInfo")
public class BoatMachineWorkingInfoController extends BaseController {
    @Autowired
    private IBoatMachineWorkingInfoService boatMachineWorkingInfoService;

    /**
     * 查询船舶工况信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(BoatMachineWorkingInfo boatMachineWorkingInfo) {
        startPage();
        List<BoatMachineWorkingInfo> list = boatMachineWorkingInfoService.selectBoatMachineWorkingInfoList(boatMachineWorkingInfo);
        return getDataTable(list);
    }

    /**
     * 导出船舶工况信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "船舶工况信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoatMachineWorkingInfo boatMachineWorkingInfo) {
        List<BoatMachineWorkingInfo> list = boatMachineWorkingInfoService.selectBoatMachineWorkingInfoList(boatMachineWorkingInfo);
        ExcelUtil<BoatMachineWorkingInfo> util = new ExcelUtil<BoatMachineWorkingInfo>(BoatMachineWorkingInfo.class);
        util.exportExcel(response, list, "船舶工况信息数据");
    }

    /**
     * 获取船舶工况信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(boatMachineWorkingInfoService.selectBoatMachineWorkingInfoById(id));
    }

    /**
     * 新增船舶工况信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "船舶工况信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoatMachineWorkingInfo boatMachineWorkingInfo) {
        return toAjax(boatMachineWorkingInfoService.insertBoatMachineWorkingInfo(boatMachineWorkingInfo));
    }

    /**
     * 修改船舶工况信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "船舶工况信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoatMachineWorkingInfo boatMachineWorkingInfo) {
        return toAjax(boatMachineWorkingInfoService.updateBoatMachineWorkingInfo(boatMachineWorkingInfo));
    }

    /**
     * 删除船舶工况信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "船舶工况信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(boatMachineWorkingInfoService.deleteBoatMachineWorkingInfoByIds(ids));
    }
}
